//
//  LJKnowledgeInfoCell.m
//  LJDemo
//
//  Created by 蔡万鸿 on 16/5/29.
//  Copyright © 2016年 黄花菜. All rights reserved.
//

#import "LJKnowledgeInfoCell.h"

@interface LJKnowledgeInfoCell ()
@property (weak, nonatomic) IBOutlet UIButton *aLevelButton;
@property (weak, nonatomic) IBOutlet UIButton *bLevelButton;
@property (weak, nonatomic) IBOutlet UIButton *decButton;
@property (weak, nonatomic) IBOutlet UIButton *addButton;
@end

@implementation LJKnowledgeInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:self.oldPriceLable.text];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, self.oldPriceLable.text.length)];
    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, self.oldPriceLable.text.length)];
    [self.oldPriceLable setAttributedText:attri];
    self.decButton.layer.cornerRadius = self.decButton.frame.size.height/2;
    self.addButton.layer.cornerRadius = self.addButton.frame.size.height/2;
    self.aLevelButton.layer.cornerRadius = 5.f;
    self.aLevelButton.layer.borderWidth = 1.f;
    self.aLevelButton.layer.borderColor = [UIColor colorWithRed:58.f/255.f green:165.f/255.f blue:95.f/255.f alpha:1].CGColor;
    self.bLevelButton.layer.cornerRadius = 5.f;
    self.bLevelButton.layer.borderWidth = 1.f;
    self.bLevelButton.layer.borderColor = [UIColor colorWithRed:58.f/255.f green:165.f/255.f blue:95.f/255.f alpha:1].CGColor;
}

+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView {
    static NSString *ID = @"KnowledgeInfoCell";
    UINib *nib = [UINib nibWithNibName:@"LJKnowledgeInfoCell" bundle: [NSBundle mainBundle]];
    [collectionView registerNib:nib forCellWithReuseIdentifier:ID];
    LJKnowledgeInfoCell *cell = [[LJKnowledgeInfoCell alloc] init];
    return cell;
}

- (IBAction)levelAction:(id)sender {
    UIButton *levelButton = (UIButton *)sender;
    if (1 == levelButton.tag) {
        self.aLevelButton.backgroundColor = [UIColor colorWithRed:58.f/255.f green:165.f/255.f blue:95.f/255.f alpha:1];
        [self.aLevelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.bLevelButton.backgroundColor = [UIColor whiteColor];
        [self.bLevelButton setTitleColor:[UIColor colorWithRed:58.f/255.f green:165.f/255.f blue:95.f/255.f alpha:1] forState:UIControlStateNormal];
    }
    else {
        self.bLevelButton.backgroundColor = [UIColor colorWithRed:58.f/255.f green:165.f/255.f blue:95.f/255.f alpha:1];
        [self.bLevelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.aLevelButton.backgroundColor = [UIColor whiteColor];
        [self.aLevelButton setTitleColor:[UIColor colorWithRed:58.f/255.f green:165.f/255.f blue:95.f/255.f alpha:1] forState:UIControlStateNormal];
    }
}

- (IBAction)decAction:(id)sender {
    if (self.countLable.text.integerValue > 1) {
        NSInteger count = self.countLable.text.integerValue - 1;
        self.countLable.text = [NSString stringWithFormat:@"%@",@(count)];
    }
}

- (IBAction)addAction:(id)sender {
    if (self.countLable.text.integerValue < 100) {
        NSInteger count = self.countLable.text.integerValue + 1;
        self.countLable.text = [NSString stringWithFormat:@"%@",@(count)];
    }
}


@end
